#encoding=utf-8
from __future__ import division

import sys
import os
import datetime
import time
import math
import ujson
import uuid
import urllib
from urlparse import urlparse, parse_qsl

import requests
from django.contrib import auth
from django.template import RequestContext
from django.core.cache import cache
from django_redis import get_redis_connection
from django.core.servers.basehttp import FileWrapper
from django.http import StreamingHttpResponse
from django.shortcuts import render_to_response, HttpResponse, HttpResponseRedirect
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.models import User
from django.db.models import Count, Max, F, Q
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from  xadmin.views.base import  CommAdminView,ModelAdminView, SortedDict, filter_hook
from django.views.generic import View
import xadmin

from gm_site import settings
from websys.models import (
ServerInfo,
)


@csrf_exempt
def hxh_user_register(request):
    now = datetime.datetime.now()
    body = request.body
    data = ujson.loads(body)
    uid = data["uid"]
    pf = data["pf"]
    pf1 = data["pf1"]
    user_info = HXHUserInfo()
    user_info.uid = uid
    user_info.pf = pf
    user_info.pf1 = pf1
    user_info.body = body
    user_info.create_date = now
    user_info.save()

@csrf_exempt
def hxh_user_pay(request):
    now = datetime.datetime.now()
    body = request.body
    data = ujson.loads(body)
    order_id = data["order_id"]
    uid = data["uid"]
    money = data["money"]
    pay_info = HXHPayInfo()
    pay_info.order_id = order_id
    pay_info.uid = uid
    pay_info.money = money
    pay_info.body = body
    pay_info.create_date = now
    pay_info.save()

#对话框测试
@csrf_exempt
def testbox(request):
    return render(request, 'test_box.html', {'string': ''})


def testbox123(request,path):
    return render(request, str(path)+'.html', {'string': ''})

from django.contrib.admin.views.decorators import staff_member_required
# @staff_member_required
# def testpage(request):
#     t_cont=RequestContext(request)
#     t_init_cont=ModelAdminView.get_context
#     print(t_init_cont,'---testpage------',t_cont)
#     return render_to_response('my_template.html',  context_instance=t_init_cont)
#
#     return render(request, 'xadmin/base_site.html', {'string': ''})

from django.contrib.admin.views.decorators import staff_member_required
from django.utils.text import capfirst
from xadmin.util import static, json, vendor, sortkeypicker
from adminx import AdminSettings
from xadmin.views.base import BaseAdminPlugin
from django.utils.translation import ugettext as _
from  xadmin.plugins.topnav import TopNavPlugin

# class AboutView(CommAdminView):
#     template_name = "my_template.html"
#     #from myproject.admin_site import custom_admin_site
#     # from andy_manager.admin_site import custom_admin_site
#     # from django.contrib.admin import AdminSite
#     # AdminSite.ge


